<html lang="en">

    <head>
        <script type="text/javascript" language="JavaScript">
            function start() {
                const source = new EventSource("http://localhost:80/api/?TOKEN=6B72D88B4255450797D2FA4786BC77F2&ctype=ADMIN.WEB&apis=%5B%7B%22api%22%3A%22v1%2Flive-scores%22%2C%22params%22%3A%7B%22homeTeam%22%3A%20%22Arsenal%22%2C%22awayTeam%22%3A%20%22Tottenham%22%2C%22homeScore%22%3A%200%2C%22awayScore%22%3A%201%7D%7D%5D");

                const dealEvent = (event) => {
                    const result = JSON.parse(event.data).result;
                    if (result === "000000") {

                    } else if (result === "000001") {
                        // event.target.close();
                    }else {
                        event.target.close();
                    }

                    const newElement = document.createElement("li");
                    const eventList = document.getElementById("list");

                    newElement.textContent = `message: ${event.data}`;
                    eventList.appendChild(newElement);

                };

                source.onmessage = dealEvent;

                source.addEventListener("172.100.91.31:8080", dealEvent)

                source.onerror = (event) => {
                    console.error("EventSource failed:", event);
                    // window.alert(event);
                    // event.target.close();
                };
            }
        </script>
        <title>SSE</title>
    </head>

    <body>
        <h1>Hello SSE!</h1>
        <button onclick="start()">Start</button>
        <ul id="list"></ul>
    </body>
</html>